home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 242 / Issue 242 - April 2008 - DPCS0408DVD.ISO / Software Money Savers / VirtualDub / Source / VirtualDub-1.7.7-src.7z / src / system / source / event.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-11-05  |  2.6 KB  |  82 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    System library component
  3. //    Copyright (C) 1998-2006 Avery Lee, All Rights Reserved.
  4. //
  5. //    Beginning with 1.6.0, the VirtualDub system library is licensed
  6. //    differently than the remainder of VirtualDub.  This particular file is
  7. //    thus licensed as follows (the "zlib" license):
  8. //
  9. //    This software is provided 'as-is', without any express or implied
  10. //    warranty.  In no event will the authors be held liable for any
  11. //    damages arising from the use of this software.
  12. //
  13. //    Permission is granted to anyone to use this software for any purpose,
  14. //    including commercial applications, and to alter it and redistribute it
  15. //    freely, subject to the following restrictions:
  16. //
  17. //    1.    The origin of this software must not be misrepresented; you must
  18. //        not claim that you wrote the original software. If you use this
  19. //        software in a product, an acknowledgment in the product
  20. //        documentation would be appreciated but is not required.
  21. //    2.    Altered source versions must be plainly marked as such, and must
  22. //        not be misrepresented as being the original software.
  23. //    3.    This notice may not be removed or altered from any source
  24. //        distribution.
  25.  
  26. #include "stdafx.h"
  27. #include <vd2/system/vdtypes.h>
  28. #include <vd2/system/event.h>
  29.  
  30. ///////////////////////////////////////////////////////////////////////////////
  31.  
  32. VDDelegate::VDDelegate() {
  33.     mpPrev = mpNext = this;
  34. }
  35.  
  36. VDDelegate::~VDDelegate() {
  37.     VDDelegateNode *next = mpNext;
  38.     VDDelegateNode *prev = mpPrev;
  39.     prev->mpNext = next;
  40.     next->mpPrev = prev;
  41. }
  42.  
  43. ///////////////////////////////////////////////////////////////////////////////
  44.  
  45. VDEventBase::VDEventBase() {
  46.     mAnchor.mpPrev = mAnchor.mpNext = &mAnchor;
  47. }
  48.  
  49. VDEventBase::~VDEventBase() {
  50.     while(mAnchor.mpPrev != &mAnchor)
  51.         Remove(static_cast<VDDelegate&>(*mAnchor.mpPrev));
  52. }
  53.  
  54. void VDEventBase::Add(VDDelegate& dbase) {
  55.     VDDelegateNode *next = mAnchor.mpNext;
  56.  
  57.     VDASSERT(dbase.mpPrev == &dbase);
  58.  
  59.     mAnchor.mpNext = &dbase;
  60.     dbase.mpPrev = &mAnchor;
  61.     dbase.mpNext = next;
  62.     next->mpPrev = &dbase;
  63. }
  64.  
  65. void VDEventBase::Remove(VDDelegate& dbase) {
  66.     VDASSERT(dbase.mpPrev != &dbase);
  67.  
  68.     VDDelegateNode *next = dbase.mpNext;
  69.     VDDelegateNode *prev = dbase.mpPrev;
  70.     prev->mpNext = next;
  71.     next->mpPrev = prev;
  72.     dbase.mpPrev = dbase.mpNext = &dbase;
  73. }
  74.  
  75. void VDEventBase::Raise(void *src, const void *info) {
  76.     for(VDDelegateNode *node = mAnchor.mpNext; node != &mAnchor; node = node->mpNext) {
  77.         VDDelegate& dbase = static_cast<VDDelegate&>(*node);
  78.  
  79.         dbase.mpCallback(src, info, dbase);
  80.     }
  81. }
  82.